<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="https://cdn.bootcss.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet">

    <script>

        TASKID = null;

        $(function () {
            var list = "plugin/list";
            $.get(
                list,
                function (text) {
                    if (text.code==200){
                        for(i in text.data)
                        {
                            var data = text.data[i];
                            var tab= "<li><a href='#"+data.plugin_key+"' data-toggle='tab'>"+data.base_info.title+"</a></li>";
                            var c = "<p>插件描述："+data.base_info.desc+"</p>"
                                +"<p>插件作者："+data.base_info.author+"</p>"
                            +"<p>相关链接："+data.base_info.link+"</p>"
                            +"<p>是否异步："+data.plugin_rule.sync+"</p>"
                            +"<p>websocket："+data.plugin_rule.websocket+"</p>";

                            c+='<form class="form-horizontal" action="plugin/use">\n';
                            c+="<input type='hidden' name='key' value='"+data.plugin_key+"'>";
                            var def = data.plugin_rule.def_params;
                            var desc = data.plugin_rule.desc_params;
                            var params = data.plugin_rule.params;
                            for (j in params){
                                var param = params[j];
                                var defv = params.length == def.length ? def[j] : "";
                                var descv = params.length == desc.length ? desc[j] : "";

                                c+= '    <div class="control-group">\n' +
                                    '        <label class="control-label">'+param+'('+descv+')</label>\n' +
                                    '        <div class="controls">\n' +
                                    '            <input name="'+param+'" type="text" value="'+defv+'" />\n' +
                                    '        </div>\n' +
                                    '    </div>\n';
                            }
                            c+="<div class=\"control-group\">\n" +
                                "    <div class=\"controls\">\n" +
                                "        <button type=\"submit\">提交</button>\n" +
                                "    </div>\n" +
                                "</div></form>";
                            var content = "<div class='tab-pane' id='"+data.plugin_key+"'>"+c+"</div>";

                            $(".nav").append(tab);
                            $(".tab-content").append(content);
                        }
                    }
                },
                "json");


        });

        function stop(t){
            $.post(
                "task/stop",
                {task:t},
                function(data){
                    if(data['code']==200){
                        alert("成功");
                    }else{
                        alert("失败");
                    }
                },
                "json"
            );
        }
        function progress(t){
            $.post(
                "task/progress",
                {task:t},
                function(data){
                    if(data['code'] == 200){
                        //var rate = data['data']*100;
                        var rate = (data['data'])*100;

                        $("#progress").attr("style","width: "+rate+"%;");
                    }
                },
                "json"
            );
        }

        function data(t){
            $.post(
                "task/data",
                {task:t},
                function(data){
                    if(data['code'] == 200){
                        var arr = data['data'];
                        var vulns = JSON.stringify(arr['vulns']);
                        var base = (arr['data']);
                        $("#base").val(base);
                        $("#vulns").val(vulns);
                    }else{
                        alert(data['msg']);
                    }
                },
                "json"
            );
        }

    </script>
</head>
<body>

<div class='container-fluid'>
    <h2 class='page-header'>Trackray</h2>

    <div class='tabbable tabs-left'>
        <ul class='nav nav-tabs'>
            <li class='active'><a href='#scanner' data-toggle='tab'>扫描器</a></li>
        </ul>

        <!--
          选项卡的内容定义
        -->
        <div class='tab-content'>
            <div class='tab-pane active' id='scanner'>
                <a href="#create"  data-toggle='tab'>创建任务</a>
                <a href="#viewData"  data-toggle='tab'>查看数据</a>

            </div>
            <div class='tab-pane ' id='viewData'>
                <div class="col-md-12 column">
                    <label >进度</label>
                    <div class="progress progress-striped active progress-info" >
                        <div id="progress" class="bar" style="width:0%"></div>
                    </div>
                    <div class="form-group">
                        <label >基本信息</label>
                        <textarea class="form-control" id="base"></textarea>
                    </div>
                    <div class="form-group">
                        <label >漏洞集合</label>
                        <textarea class="form-control" id="vulns"></textarea>
                    </div>
                    <br/>
                    <button class="btn btn-default"  onclick="pull()" type="button">pull</button>
                    <button class="btn btn-default" onclick="kill(TASKID)" type="button">kill</button>
                    <script>
                        function pull() {
                            if (TASKID==null)
                                return;
                            setInterval("progress(TASKID)",3000);
                            setInterval("data(TASKID)",3000);
                        }
                    </script>
                </div>
            </div>
            <div class='tab-pane ' id='create'>
                <div class="col-md-12 column">
                    <form id="form_create" role="form">
                        <div class="form-group">
                            <label >任务名</label><input class="form-control" type="text" name="name" value="test"/>
                            <label >扫描地址</label><input class="form-control" type="text" name="target" value="http://testphp.vulnweb.com/"/>
                            <label >Cookie</label><input class="form-control" type="text" name="cookie" />
                            <label >线程数(最大50)</label><input class="form-control" type="text" name="thread"  value="50"/>
                            <label >爬虫广度(最大500)</label><input class="form-control" type="text" name="spiderMax" value="300"/>
                            <label >爬虫深度(写2就行)</label><input class="form-control" type="text" name="spiderDeep" value="2"/>
                            <label >最大扫描时间(毫秒)</label><input class="form-control" type="text" name="timeMax" value="100000"/>
                            <label >代理池(json格式)</label><textarea class="form-control" name="proxy" /></textarea>
                        </div>
                        <div class="form-group">
                            <label >扫描规则</label>
                            <label><input type="checkbox" value="true" name="rule.crawler" />爬虫</label>
                            <label><input type="checkbox" value="true" name="rule.sense" />资产扫描</label>
                            <label><input type="checkbox" value="true" name="rule.port" />端口扫描</label>
                            <label><input type="checkbox" value="true" name="rule.finger" />指纹识别</label>
                            <label><input type="checkbox" value="true" name="rule.childdomain" />子域名</label>
                            <label><input type="checkbox" value="true" name="rule.fuzzdir" />目录扫描</label>
                            <label><input type="checkbox" value="true" name="rule.attack" />漏洞模块攻击</label>
                            <label><input type="checkbox" value="true" name="rule.thorough" />深度扫描</label>
                            <div class="checkbox">
                            </div>
                        </div> <button id="create_button" type="button" class="btn btn-default">开始</button>
                    </form>
                    <script>
                        $(function () {
                           $("#create_button").click(function () {
                               $.ajax({
                                   url:"task/create",
                                   type:"post",
                                   dataType:'json',
                                   data: $('#form_create').serialize(),
                                   success:function (data) {
                                       if (data.code==200){
                                           var md5 = data.data;
                                           $.post(
                                               "task/start",
                                               {task:md5},
                                               function (text) {
                                                   if (text.code==200){
                                                       alert("正在扫描请等待");
                                                       TASKID = md5;
                                                   }else{
                                                       alert(text.msg);
                                                   }
                                               },
                                               "json"
                                           );

                                       }else{
                                           alert(data.msg);
                                       }
                                   }
                               });
                           });

                        });
                    </script>
                </div>

            </div>
        </div>
    </div>

</div>

</body>
</html>